import json
import time
import threading
import WxMsgDeal
from flask import Flask, request

# 定义收到请求数据后返回数据
return_data = {"code": 200, "msg": "ok", "timestamp": int(time.time() * 1000)}

app = Flask(__name__)


@app.route('/wechat/', methods=['POST'])
def judge():
    data = request.get_data().decode('UTF-8')
    data = json.loads(data)
    if data['type'] == 'D0001':  # 注入成功
        one = threading.Thread(target=WxMsgDeal.get_injection_msg, args=(data,))
        one.start()
    elif data['type'] == 'D0002':  # 登录成功
        two = threading.Thread(target=WxMsgDeal.get_login_success_msg, args=(data,))
        two.start()
    elif data['type'] == 'D0003':  # 收到消息
        three = threading.Thread(target=WxMsgDeal.get_msg, args=(data,))
        three.start()
    elif data['type'] == 'D0004':  # 转账事件
        pass
    elif data['type'] == 'D005':  # 撤回事件
        pass
    elif data['type'] == 'D006':  # 好友请求
        pass

    # 向客户端返回表示收到数据
    return '{"code": 200, "msg": "ok", "timestamp": int(time.time() * 1000)}'.encode()
    # 处理客户端发送的数据


if __name__ == '__main__':
    app.run(port=8089, debug=False)
